
package com.ce.cases.report.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.ce.cases.report.view.ReportTaxIllegalView;
import com.ce.framework.datamaintain.action.SearchAction;
import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.DateUtil;
import com.ce.framework.util.StringUtil;
import com.ce.sys.login.model.User;
import com.ce.sys.org.dao.po.SysVOrg;
import com.ce.util.OrgUtil;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2014-03-12
* 创建时间：14:08:23
* 功能描述：检举信息台账 [REPORT_TAX_ILLEGAL]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class ReportTaxIllegalSearchCondition  extends SQLSearchCondition
	implements ISQLMapper
{
    private String regNumber;
    private String repDept;
    private String repType;
    private String beginRepDate;
    private String endRepDate;
    private String repPerson;
    private String repPersonPhone;
    private String _dealWay;
    private String beginCloseDate;
    private String endCloseDate;
    private String regDept;
    private String inspectDept;
    private String collectDept;
    private String directorPassFlag;
    private String opMenu;
    
    
    private String caseOf;
    
    private String curOrgId;
    
    private String curOrgLevel;
    private String curOrgType;
    
    private String curRootOrgId;
    private String curPersonId;
    private String curRootOrgLevel;
    private String curPersonPosition;//当前人职位
    
    @Override
	public void initCondition(SearchAction action, boolean search)
			throws AppException {
		User user=User.getUser();
		SysVOrg curOrg=OrgUtil.getOrg(User.getUserOrgId());
		this.curOrgId=curOrg.getVcId();
		this.curOrgLevel=curOrg.getVcOrgLevel();
		this.curPersonId=User.getUserId();
		this.curOrgType=curOrg.getVcType();
		curRootOrgId=user.getRootOrgId();
		curPersonPosition=user.getVcPosition();
		curRootOrgLevel=user.getRootOrgLevel();
		
	}
  
    @Override
	public String getExcelName() {
		return this.getExcelTitle()+"_"+DateUtil.format(new Date(),"yyyyMMddHHmm");
	}
    public String getExcelTitle(){
		String excelName="";
		if("caseSource".equals(opMenu)){
			excelName="案源台账";
		}else if("replyReward".equals(opMenu)){
			excelName="回复奖励登记表";  
		}else{
			excelName="检举信息台账";  
		}
		return excelName;
	}
	public String getSearchSql() throws AppException {
		
		StringBuffer sql = new StringBuffer("");
		if(StringUtil.isNotBlank(caseOf)){
			sql.append(" select t.*,work.VC_STATUS,(select f.VC_STATUS from T_WORKFLOW_FLOW f where f.VC_RECORD_ID=VC_RECORD_ID and f.VC_WORK_ID=work.vc_id and f.VC_SEQUENCE=work.vc_Status) as vcStatus_ from REPORT_TAX_ILLEGAL t,CASE_SOURCE case,T_WORKFLOW_WORK work where t.vc_id=case.REPORT_ID and case.vc_id=work.VC_RECORD_ID and case.VC_DEL$FLAG = 0 and t.VC_DEL$FLAG = 0 ");
		}else{
			sql.append("select t.*,''  VC_STATUS,''  vcStatus_  from REPORT_TAX_ILLEGAL t where t.VC_DEL$FLAG = 0");
		}
		
		
		if("3".equals(this.curOrgLevel)&&"2".equals(this.curOrgType)){//跨区局
			if("01 02 ".contains(curPersonPosition)){//局长 副局长
				sql.append(" and t.INSPECTION_DEPT_ID='"+curRootOrgId+"' ");
			}else if("10 09 ".contains(curPersonPosition)){
				sql.append(" and t.REGISTER_DEPT_ID='"+curOrgId+"' ");
			}else{
				sql.append(" and t.DEAL_RESULT=21 ");
			}
			
		}else if("3".equals(this.curOrgLevel)&&"1".equals(this.curOrgType)){//征管局
			sql.append(" and (t.REGISTER_DEPT_ID='"+curOrgId+"' or t.COLLECTION_DEPT_ID='"+curRootOrgId+"' and t.DEAL_RESULT=1)");
		}
		/*=========自行修改该处代码================
		//实现排序的代码
		sql.append(" "+super.getOrderBy());
		======================================*/
		
		
		
		if(StringUtil.isNotBlank(regNumber)){
			sql.append(" and t.TAXPAYER_NUMBER like '%"+regNumber+"%'");
		}
		if(StringUtil.isNotBlank(repDept)){
			sql.append(" and t.TAX_ENTERPRICE like '%"+repDept+"%'");
		}
		if(StringUtil.isNotBlank(repType)){
			sql.append(" and t.report_type_num='"+repType+"'");
		}
		/*
		 * 2015-06-09 by 刘渝洪，开始 
		 * 修改搜索处理，此处为【检举信息台帐】和【检举案源台帐】公用，需分别处理
		 * 【检举信息台帐】：
		 * 默认初始列表时，或搜索日期条件没值时，搜索出的结果为：本年度的检举信息数据
		 * 设置搜索日期条件时，搜索出的结果为：满足日期条件的检举信息数据
		 * 【检举案源台帐】：
		 * 默认初始列表时，或搜索日期条件没值时，搜索出的结果为：全部未结案的数据，以及本年度的已结案数据
		 * 设置搜索日期条件时，搜索出的结果为：满足日期条件的全部数据
		 * 原代码：
		 * sql.append(this.getDateCondition("REPORT_TIME", beginRepDate, endRepDate));
		 * 修改后代码：
		 */
		if (StringUtil.isNotBlank(beginRepDate)
				|| StringUtil.isNotBlank(endRepDate)) {
			sql.append(this.getDateCondition("REPORT_TIME", beginRepDate, endRepDate));
		} else {
			if(StringUtil.isNotBlank(caseOf)){
				sql.append(" and (to_number(work.vc_status)<>9 or (to_number(work.vc_status)=9 ");
			}
			String dateBeginOfThisYear = DateUtil.getYear() + "-01-01 00:00:00";
			String dateEndOfThisYear = DateUtil.getYear() + "-12-31 23:59:59";
			sql.append(" and ").append("REPORT_TIME").append(">=to_date('")
					.append(dateBeginOfThisYear)
					.append("','yyyy-mm-dd hh24:mi:ss') ");
			sql.append(" and ").append("REPORT_TIME").append("<=to_date('")
					.append(dateEndOfThisYear)
					.append("','yyyy-mm-dd hh24:mi:ss') ");
			if(StringUtil.isNotBlank(caseOf)){
				sql.append("))");
			}
		}
		/* 2015-06-09 by 刘渝洪，结束 */
		
		if(StringUtil.isNotBlank(repPerson)){
			sql.append(" and t.report_person like '%"+repPerson+"%'");
		}
		if(StringUtil.isNotBlank(repPersonPhone)){
			sql.append(" and t.contact_number like '%"+repPersonPhone+"%'");
		}
		if(StringUtil.isNotBlank(_dealWay)){
			sql.append(" and t.deal_result='"+_dealWay+"'");
		}
		
		if(StringUtil.isNotBlank(regDept)){
			sql.append(" and t.regist_dept_id='"+regDept+"'");
		}
		
		if(StringUtil.isNotBlank(inspectDept)){
			sql.append(" and t.inspection_dept_id='"+inspectDept+"'");
		}
		
		if(StringUtil.isNotBlank(collectDept)){
			sql.append(" and t.collection_dept_id='"+collectDept+"'");
		}
		if(StringUtil.isNotBlank(directorPassFlag)){
			sql.append(" and t.DIRECTOR_PASS_FLAG="+directorPassFlag+"");
		}
		//案源
		if("caseSource".equals(opMenu)){
		  //sql.append(" and t.state>=");	
		}else if("replyReward".equals(opMenu)){//回复奖励登记
		  //sql.append(" and t.state>=");
		}
		//排序
		if(StringUtil.isNotBlank(this.order)){
            sql.append(" order by "+ this.getOrderByUnderLine());
		}else{
			 sql.append(" order by report_Time desc");
		}
		return sql.toString();
	}
	
	public Object fromSQLQuery(ResultSet rs, int num) {
		ReportTaxIllegalView view = new ReportTaxIllegalView();
		try {

			view.setVcId(rs.getString("VC_ID"));
			view.setCode(rs.getString("CODE"));
			view.setRegisterPerson(rs.getString("REGISTER_PERSON"));
			view.setRegisterDept(rs.getString("REGISTer_DEPT"));
			view.setRegisterDate(rs.getDate("REGISTER_DATE"));
			view.setRecorder(rs.getString("RECORDER"));
			view.setRecordDate(rs.getDate("RECORD_DATE"));
			view.setReportFromName(rs.getString("REPORT_FROM_NAME"));
			view.setReportPerson(rs.getString("REPORT_PERSON"));
			view.setReportTime(rs.getDate("REPORT_TIME"));
			view.setReportDept(rs.getString("REPORT_DEPT"));
			view.setCertificatesName(rs.getString("CERTIFICATES_NAME"));
			view.setCertificatesCode(rs.getString("CERTIFICATES_CODE"));
			view.setContactNumber(rs.getString("CONTACT_NUMBER"));
			view.setReportTypeName(rs.getString("REPORT_TYPE_NAME"));
			view.setReportPersonAddr(rs.getString("REPORT_PERSON_ADDR"));
			view.setReportCount(rs.getInt("REPORT_COUNT"));
			view.setProsecutedPerson(rs.getString("PROSECUTED_PERSON"));
			view.setRegistrationType(rs.getString("REGISTRATION_TYPE"));
			view.setTaxpayerNumber(rs.getString("TAXPAYER_NUMBER"));
			view.setTaxEnterprice(rs.getString("TAX_ENTERPRICE"));
			view.setLegalPerson(rs.getString("LEGAL_PERSON"));
			view.setInspectionDept(rs.getString("INSPECTION_DEPT"));
			view.setCollectionDept(rs.getString("COLLECTION_DEPT"));
			view.setProsecutedPersonAddr(rs.getString("PROSECUTED_PERSON_ADDR"));
			view.setProsecutedTel(rs.getString("PROSECUTED_TEL"));
			view.setReportData(rs.getString("REPORT_DATA"));
			view.setReportContent(rs.getString("REPORT_CONTENT"));
			view.setDirector(rs.getString("DIRECTOR"));
			view.setDirectorApprDate(rs.getDate("DIRECTOR_APPR_DATE"));
			view.setDirectorAdvice(rs.getString("DIRECTOR_ADVICE"));
			view.setDirectorPassFlag(rs.getInt("DIRECTOR_PASS_FLAG"));
			view.setNote(rs.getString("NOTE"));
			view.setDealResult(rs.getInt("DEAL_RESULT"));
			view.setReplyWay(rs.getString("REPLY_WAY"));
			if("1".equals(rs.getString("IS_REWARD"))){
				if(rs.getDouble("REWARD_MONEY")>0){
					view.setRewardResult("奖励"+rs.getDouble("REWARD_MONEY")+"元");
				}else{
					view.setRewardResult("奖励");
				}
					
			}else if("0".equals(rs.getString("IS_REWARD"))){
				view.setRewardResult("不奖励");
			}
			view.setState(rs.getInt("VC_STATUS"));
			view.setStatus(rs.getInt("vcStatus_"));
			view.setEvoke(rs.getString("evoke"));
			view.setVcDelFlag(rs.getInt("VC_DEL$FLAG"));			

		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return view;
	}
	
	public ISQLMapper getSQLMapper() {
		
		return this;
	}

	public String getRegNumber() {
		return regNumber;
	}

	public void setRegNumber(String regNumber) {
		this.regNumber = regNumber;
	}

	public String getRepDept() {
		return repDept;
	}

	public void setRepDept(String repDept) {
		this.repDept = repDept;
	}

	public String getRepType() {
		return repType;
	}

	public void setRepType(String repType) {
		this.repType = repType;
	}

	public String getBeginRepDate() {
		return beginRepDate;
	}

	public void setBeginRepDate(String beginRepDate) {
		this.beginRepDate = beginRepDate;
	}

	public String getEndRepDate() {
		return endRepDate;
	}

	public void setEndRepDate(String endRepDate) {
		this.endRepDate = endRepDate;
	}

	public String getRepPerson() {
		return repPerson;
	}

	public void setRepPerson(String repPerson) {
		this.repPerson = repPerson;
	}

	public String getRepPersonPhone() {
		return repPersonPhone;
	}

	public void setRepPersonPhone(String repPersonPhone) {
		this.repPersonPhone = repPersonPhone;
	}

	public String get_dealWay() {
		return _dealWay;
	}

	public void set_dealWay(String _dealWay) {
		this._dealWay = _dealWay;
	}

	public String getBeginCloseDate() {
		return beginCloseDate;
	}

	public void setBeginCloseDate(String beginCloseDate) {
		this.beginCloseDate = beginCloseDate;
	}

	public String getEndCloseDate() {
		return endCloseDate;
	}

	public void setEndCloseDate(String endCloseDate) {
		this.endCloseDate = endCloseDate;
	}

	public String getRegDept() {
		return regDept;
	}

	public void setRegDept(String regDept) {
		this.regDept = regDept;
	}

	public String getInspectDept() {
		return inspectDept;
	}

	public void setInspectDept(String inspectDept) {
		this.inspectDept = inspectDept;
	}

	public String getCollectDept() {
		return collectDept;
	}

	public void setCollectDept(String collectDept) {
		this.collectDept = collectDept;
	}

	public String getOpMenu() {
		return opMenu;
	}

	public void setOpMenu(String opMenu) {
		this.opMenu = opMenu;
	}

	public String getCurOrgId() {
		return curOrgId;
	}

	public void setCurOrgId(String curOrgId) {
		this.curOrgId = curOrgId;
	}

	public String getCurPersonId() {
		return curPersonId;
	}

	public void setCurPersonId(String curPersonId) {
		this.curPersonId = curPersonId;
	}

	public String getCurOrgLevel() {
		return curOrgLevel;
	}

	public void setCurOrgLevel(String curOrgLevel) {
		this.curOrgLevel = curOrgLevel;
	}

	public String getCaseOf() {
		return caseOf;
	}

	public void setCaseOf(String caseOf) {
		this.caseOf = caseOf;
	}

	public String getCurOrgType() {
		return curOrgType;
	}

	public void setCurOrgType(String curOrgType) {
		this.curOrgType = curOrgType;
	}

	public String getCurRootOrgId() {
		return curRootOrgId;
	}

	public void setCurRootOrgId(String curRootOrgId) {
		this.curRootOrgId = curRootOrgId;
	}

	public String getCurRootOrgLevel() {
		return curRootOrgLevel;
	}

	public void setCurRootOrgLevel(String curRootOrgLevel) {
		this.curRootOrgLevel = curRootOrgLevel;
	}

	public String getCurPersonPosition() {
		return curPersonPosition;
	}

	public void setCurPersonPosition(String curPersonPosition) {
		this.curPersonPosition = curPersonPosition;
	}

	public String getDirectorPassFlag() {
		return directorPassFlag;
	}

	public void setDirectorPassFlag(String directorPassFlag) {
		this.directorPassFlag = directorPassFlag;
	}
	
	

}

